luogu2114 [NOI2014]起床困难综合症 发表于 2018-04-11 12345贪心从高到低每一位考虑放0还是10能造成伤害就放0否则,1能造成就放1否则,不放 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include<bits/stdc++.h>#define mp make_pair#define pb push_backusing namespace std;typedef long long LL;typedef pair<int,int> PII;inline LL read(){ LL x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*f;}const int N=100008;int n,m,maxi,ans;char s[5];struct node{ int type,x; inline int calc(const int &y){ if(type==0){ return x|y; } else if(type==1){ return x&y; } else{ return x^y; } }}a[N];inline int solve(int x){ for(int i=1;i<=n;++i){ x=a[i].calc(x); } return x;}int main(){ n=read();m=read(); for(int i=1;i<=n;++i){ scanf("%s",s); if(s[0]=='O'){ a[i].type=0; } else if(s[0]=='A'){ a[i].type=1; } else{ a[i].type=2; } a[i].x=read(); } for(maxi=1;maxi<=m;maxi<<=1); for(maxi>>=1;maxi;maxi>>=1){ if(solve(0)&maxi){ continue; } if((ans^maxi)<=m&&(solve(maxi)&maxi)){ ans^=maxi; } } printf("%d",solve(ans)); return 0;}